﻿$(function () {
    $("input[class*=:required]").after("<span> *</span>")
});
//弹出信息样式设置
Vanadium.config = {
    valid_class: 'rightformcss', //验证正确时表单样式
    invalid_class: 'failformcss', //验证失败时该表单样式
    message_value_class: 'msgvaluecss', //这个样式是弹出信息中调用值的样式
    advice_class: 'failmsg', //验证失败时文字信息的样式
    prefix: ':',
    separator: ';',
    reset_defer_timeout: 100
}
//验证类型及弹出信息设置
Vanadium.Type = function (className, validationFunction, error_message, message, init) {
    this.initialize(className, validationFunction, error_message, message, init);
};
Vanadium.Type.prototype = {
    initialize: function (className, validationFunction, error_message, message, init) {
        this.className = className;
        this.message = message;
        this.error_message = error_message;
        this.validationFunction = validationFunction;
        this.init = init;
    },
    test: function (value) {
        return this.validationFunction.call(this, value);
    },
    validMessage: function () {
        return this.message;
    },
    invalidMessage: function () {
        return this.error_message;
    },
    toString: function () {
        return "className:" + this.className + " message:" + this.message + " error_message:" + this.error_message
    },
    init: function (parameter) {
        if (this.init) {
            this.init(parameter);
        }
    }
};
Vanadium.setupValidatorTypes = function () {
    Vanadium.addValidatorType('empty', function (v) {
        return ((v == null) || (v.length == 0));
    });
    //**********以下为验证方法,使用时可仅保留用到的判断
    Vanadium.addValidatorTypes([
    //是否为空
    ['required', function (v) {
        return !Vanadium.validators_types['empty'].test(v);
    }, '出错咯！此项不可为空!'],
    //输入指定范围的字符串
    ['min_length',
      function (v, p) {
          if (p === undefined) {
              return true
          } else {
              return v.length >= parseInt(p)
          }
          ;
      },
      function (_v, p) {
          return '输入字符长度不低于<span class="' + Vanadium.config.message_value_class + '">' + p + '</span>个.'
      }
    ],
    ['max_length',
      function (v, p) {
          if (p === undefined) {
              return true
          } else {
              return v.length <= parseInt(p)
          }
          ;
      },
      function (_v, p) {
          return '输入字符长度不大于<span class="' + Vanadium.config.message_value_class + '">' + p + '</span>个.'
      }
    ],
      //用户名或密码
    ['Rmin_length',
      function (v, p) {
          if (p === undefined) {
              return true
          } else {
              return v.length >= parseInt(p)
          }
          ;
      },
      function (_v, p) {
          return '出错咯！用户名和密码的字符长度不低于<span class="' + Vanadium.config.message_value_class + '">' + p + '</span>个.'
      }
    ],
    ['Rmax_length',
      function (v, p) {
          if (p === undefined) {
              return true
          } else {
              return v.length <= parseInt(p)
          }
          ;
      },
      function (_v, p) {
          return '出错咯！用户名和密码的字符长度不大于<span class="' + Vanadium.config.message_value_class + '">' + p + '</span>个.'
      }
    ],
    //邮箱验证
    ['email', function (v) {
        return (Vanadium.validators_types['empty'].test(v) || /\w{1,}[@@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(v))
    }, '出错咯！邮箱格式不正确,请检查.正确格式例如abc@123.com'],
    //手机号码验证 
    ['phone', function (v) {
        return (Vanadium.validators_types['empty'].test(v) || /^([0-9]{11})?$/.test(v))
    }, '出错咯！手机号码格式不正确,请检查.正确格式例如15201999666'],
    //学号验证
      ['StudentNo', function (v) {
          return (Vanadium.validators_types['empty'].test(v) || /^([0-9]{10})?$/.test(v))
      }, '出错咯！学号格式不正确,请检查.正确格式例如2009122142']

  ])
    if (typeof (VanadiumCustomValidationTypes) !== "undefined" && VanadiumCustomValidationTypes) Vanadium.addValidatorTypes(VanadiumCustomValidationTypes);
};